package interview.huawei;

import org.junit.jupiter.api.Test;

public class FindGrid {

    public int solution(String[] input) {
        int count = 0;
        int c = 0;
        String s1, s2, s3;
        for (int i = 0; i < input.length; i++) {
            s1 = input[i];
            for (int j = 0; j < input.length; j++) {
                if(j != i) {
                    s2 = input[j];
                    if (s1.charAt(1) == s2.charAt(0)) {
                        for (int k = 0; k < input.length; k++) {
                            c += 1;
                            if(k != j && k != i) {
                                s3 = input[k];
                                if (s1.charAt(2) == s3.charAt(0) && s2.charAt(2) == s3.charAt(1)) {
                                    count += 1;
                                    System.out.println(s1);
                                    System.out.println(s2);
                                    System.out.println(s3);
                                }
                            }
                        }
                    }
                }
            }
        }
        System.out.println(c);
        return count;
    }

    @Test
    public void test() {
        String[] input = new String[]{
                "alb", "gkl", "fda", "del"
        };
        int c = solution(input);
        System.out.println(c);
    }
}
